package dw2;


import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
/*
 * This is the basic person class used to create colored
 * Will be used for the gunner images
 */

/**
 *
 * @author Brian
 */
public class npcPeople extends NPC {
    protected int health = 1; //hits 5 times so health = 5 X lives
    protected int speed = 10;
    protected int frames = 2;
    protected int cycle_count = 0;

    protected static ArrayList<Image> image = new ArrayList<Image>();
    public static void initImage(Image images[])
    {
        image.addAll(Arrays.asList(images));
 
    }
    public npcPeople(int x, int y, int direction_to_face,int points)
    {
        super(x,y-image.get(0).getHeight(null),direction_to_face,points);
        bulletX = 10;
        ATTACK_POWER = 1;
        FIRING_RATE = 80;
        graphics.add(new DWGraphics_Animation(image.get(0),speed,frames));
        graphics.add(new DWGraphics_Animation(image.get(1),speed,1));
    }

    public void action(Main mainparent,Worm player)
    {
        cycle_count++;
        this.player = player;
        move(mainparent,player.getHeadPosition());

        if(state == 0){
            notFire();
        }
        if(state == 1){
            Fire();
            cycle_count++;
        }
        if(fire_gun(mainparent,player.getHeadPosition())){
            bulletY = y + 25;
            bulletX = x + 5;
            state = 1;
        }
        if(player.hitHead(graphics.get(graphics_index).getBounds())==true)
        {
            
            health--;
            if(health == 0){
                mainparent.bite1HardCrunch.play();
                player.countKill();
                player.add_points(points);
                deathParticles(mainparent,player);
               
                mainparent.removeNPC(this);
                return;
            }
        }
        if(cycle_count > 50){
            state = 0;
            cycle_count = 0;
        }
    }
    public void notFire(){
        graphics_index = 0;
    }

    public void Fire(){
        graphics_index = 1;
    }
}
